package com.zs.members.controller;



import com.gsj.common.pojo.R;
import com.zs.members.pojo.vo.LevelVo;
import com.zs.members.service.ILevelService;
import com.zs.members.pojo.entity.Level;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
    import org.springframework.web.bind.annotation.RestController;

/**
* <p>
    *  前端控制器
    * </p>
*
* @author 张硕
* @since 2021-07-24
*/

@Slf4j
@Api(tags = "会员等级控制")
@RestController
@RequestMapping("/members/level")
public class LevelController {

    @Autowired
    public ILevelService levelService;



    @ApiOperation(value = "根据id删除")
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") Long id){
        levelService.removeById(id);
        return R.ok();
    }


    @ApiOperation(value = "搜索并分页")
    @PostMapping("/get/{currentPage}/{pageSize}")
    public R get(@PathVariable("currentPage")Integer currentPage, @PathVariable("pageSize")Integer pageSize,@RequestBody LevelVo levelVo){

        return levelService.get(currentPage,pageSize,levelVo);
    }

    @ApiOperation(value = "查询出所有level")
    @PostMapping("/get")
    public R get(){
        List<Level> levels = levelService.list();
        return R.ok().put("levels",levels);
    }

    @ApiOperation(value = "添加和更改")
    @PostMapping("/saveOrUpdate")
    public R saveOrUpdate(@RequestBody Level level){
        levelService.saveOrUpdate(level);
        return R.ok();
    }








}
